from typing import List


class Solution:
    def twoOutOfThree(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:

        re_list = list()
        for i in nums1:
            if (i in nums2 or i in nums3) and i not in re_list:
                re_list.append(i)

        for i in nums2:
            if  i in nums3 and i not in re_list :
                re_list.append(i)
        return re_list
# 升级版
    def twoOutOfThree1(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:

        all_num_list = nums3 + nums2 + nums1
        all_num_tuple = set(all_num_list)
        re_list = list()
        for i in all_num_tuple:
            if (i in nums2 and i in nums3) or (i in nums2 and i in  nums1) or (i in nums1 and i in nums3) and i not in re_list:
                re_list.append(i)
        return re_list

    def twoOutOfThree1(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:

        all_num_list = nums3 + nums2 + nums1
        all_num_tuple = set(all_num_list)
        re_list = list()
        for i in all_num_tuple:
            if (i in nums2 and i in nums3) or (i in nums2 and i in  nums1) or (i in nums1 and i in nums3) and i not in re_list:
                re_list.append(i)
        return re_list

if __name__ == '__main__':
    nums1 = [1,2,2]
    nums2 = [4,3,3]
    nums3 = [5]

    solution = Solution()
    val = solution.twoOutOfThree(nums1, nums2, nums3)
    print(val)
    val1 = solution.twoOutOfThree1(nums1,nums2,nums3)
    print(val1)

